package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Consumption;
import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.mapper.ConsumptionItemMapper;
import cn.wolfcode.service.IConsumptionItemService;
import cn.wolfcode.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConsumptionItemServiceImpl implements IConsumptionItemService {
    @Autowired
    private ConsumptionItemMapper consumptionItemMapper;

    @Override
    public List<ConsumptionItem> selectByConsumptionItemCon(String cno) {
        return consumptionItemMapper.selectByConsumptionItemCon(cno);
    }

    @Override
    public void save(ConsumptionItem consumptionItem) {

        //设置创建时间
        consumptionItem.setCreateTime(new Date());
        //设置创建人
        consumptionItem.setCreateUserId(UserContext.getCurrentUser().getId());
        consumptionItemMapper.insert(consumptionItem);
    }

    @Override
    public void update(ConsumptionItem consumptionItem) {
        consumptionItemMapper.updateByPrimaryKey(consumptionItem);
    }

    @Override
    public void delete(Long[] ids) {
        for (Long id : ids){
            consumptionItemMapper.deleteByPrimaryKey(id);
        }
    }
}
